package com.jl.jlapp.mvp.activity;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.Adapter;
import android.support.v7.widget.RecyclerView.LayoutManager;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.jl.jlapp.R;
import com.jl.jlapp.adapter.OrderDetailsAdapter;
import com.jl.jlapp.eneity.Evaluate;
import com.jl.jlapp.eneity.ImageBean;
import com.jl.jlapp.eneity.ImgUploadModel;
import com.jl.jlapp.eneity.OrderDetail;
import com.jl.jlapp.nets.CommonObserver;
import com.jl.jlapp.nets.Net;
import com.jl.jlapp.popu.ClearHistorySearhPopu;
import com.jl.jlapp.utils.CustomLanearLayoutManager;
import com.jl.jlapp.utils.MimeTypeUtils;
import com.jl.jlapp.utils.Tools;
import com.jl.jlapp.utils.loader.Loader;
import com.yanzhenjie.permission.AndPermission;
import com.yanzhenjie.permission.PermissionNo;
import com.yanzhenjie.permission.PermissionYes;
import com.yanzhenjie.permission.Rationale;
import com.yanzhenjie.permission.RationaleListener;
import com.yzs.imageshowpickerview.ImageShowPickerBean;
import com.yzs.imageshowpickerview.ImageShowPickerListener;
import com.yzs.imageshowpickerview.ImageShowPickerView;
import com.zhihu.matisse.Matisse;
import com.zhihu.matisse.MimeType;
import com.zhihu.matisse.engine.impl.PicassoEngine;
import com.zhihu.matisse.internal.entity.CaptureStrategy;

import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.MultipartBody.Part;
import okhttp3.RequestBody;

public class UnderlineActivity
  extends AppCompatActivity
  implements OnClickListener
{
  private static final int REQUEST_CODE_CHOOSE = 233;
  private long chaoshitime;
  ClearHistorySearhPopu clearHistorySearhPopu;
  private long countdownTime;
  int fromDetailPage = -1;
  Handler handler = new Handler();
  boolean isNotOvertime = true;
  List<ImageBean> list;
  List<Evaluate> models;
  @BindView(R.id.offline_payment_submit_btn)
  TextView offlinePaymentSubmitBtn;
  int orderId = 0;
  String orderNo = "";
  @BindView(R.id.out_of_time_tips)
  TextView outOfTimeTips;
  @BindView(R.id.overtime_pay_title)
  TextView overtimePayTitle;
  MultipartBody.Part[] partList = new MultipartBody.Part[10];
  double payMoney = -1.0D;
  @BindView(R.id.pay_title)
  TextView payTitle;
  List<String> picUrlList = new ArrayList();
  @BindView(R.id.it_picker_view)
  ImageShowPickerView pickerView;
  int postagePayType = -1;
  private ProgressDialog progressDialog;
  private RationaleListener rationaleListener = new RationaleListener()
  {
    public void showRequestPermissionRationale(int paramAnonymousInt, Rationale paramAnonymousRationale)
    {
      paramAnonymousRationale.resume();
    }
  };
  List<String> realPicUrlList = new ArrayList();
  String remitterAccount = "";
  String remitterName = "";
  @BindView(R.id.rlv_order_details)
  RecyclerView rlvOrderDetails;
  Runnable runnable = new Runnable()
  {
    public void run()
    {
      if (UnderlineActivity.this.countdownTime > 1000L)
      {
        UnderlineActivity.this.isNotOvertime = true;
        Log.d("aaaaaaaa", "run: " + UnderlineActivity.this.countdownTime);
        countdownTime= countdownTime - 1000L;
        long l2 = UnderlineActivity.this.countdownTime / 1000L;
        long l1 = l2 / 3600L;
        long l3 = l2 % 3600L;
        l2 = l3 / 60L;
        l3 %= 60L;
        String str1 = l1 + "";
        if (l1 < 10L) {
          str1 = "0" + l1;
        }
        String str2 = l2 + "";
        if (l2 < 10L) {
          str2 = "0" + l2;
        }
        String str3 = l3 + "";
        if (l3 < 10L) {
          str3 = "0" + l3;
        }
        UnderlineActivity.this.timer_view.setText(str1 + ":" + str2 + ":" + str3);
        UnderlineActivity.this.handler.postDelayed(this, 1000L);
        return;
      }
      UnderlineActivity.this.isNotOvertime = false;
      UnderlineActivity.this.payTitle.setVisibility(View.GONE);
      UnderlineActivity.this.timer_view.setVisibility(View.GONE);
      UnderlineActivity.this.outOfTimeTips.setVisibility(View.GONE);
      UnderlineActivity.this.overtimePayTitle.setVisibility(View.VISIBLE);
      UnderlineActivity.this.offlinePaymentSubmitBtn.setVisibility(View.GONE);
      UnderlineActivity.this.writeUnderlineMsg.setVisibility(View.GONE);
      UnderlineActivity.this.handler.removeCallbacks(runnable);
    }
  };
  private String timefromServer;
  @BindView(R.id.timer_pay)
  TextView timer_view;
  @BindView(R.id.tv_remitter_account_details)
  EditText tvRemitterAccountDetails;
  @BindView(R.id.tv_remitter_name_details)
  EditText tvRemitterNameDetails;
  @BindView(R.id.tv_success)
  TextView tvSuccess;
  int userId = 0;
  @BindView(R.id.write_underline_msg)
  LinearLayout writeUnderlineMsg;
  
  @PermissionNo(300)
  private void getPermissionNo(List<String> paramList)
  {
    Toast.makeText(this, "未授权", Toast.LENGTH_SHORT).show();
  }
  
  @PermissionYes(300)
  private void getPermissionYes(List<String> paramList) {}
  
  private void getTimeDuring()
  {
    this.chaoshitime = 14400000L;
    if (this.postagePayType == 0) {
      this.chaoshitime = 14400000L;
    }
      SimpleDateFormat localObject = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      try
      {
        Date date= ((SimpleDateFormat)localObject).parse(this.timefromServer);
        long l1 = new Date().getTime();
        long l2 = date.getTime();
        this.countdownTime = (this.chaoshitime - (l1 - l2));
        this.handler.postDelayed(this.runnable, 1000L);
        return;
//        if (this.postagePayType != 1) {
//          continue;
//        }
//        this.chaoshitime = 86400000L;
      }
      catch (ParseException localParseException)
      {

      }
  }
  
  private void photo(List<String> paramList)
  {
    this.partList = new MultipartBody.Part[10];
    int i = 0;
    while (i < paramList.size())
    {
      Object localObject = new File((String)paramList.get(i));
      if (localObject != null)
      {
        RequestBody localRequestBody = RequestBody.create(MediaType.parse(MimeTypeUtils.getMimeType((File)localObject)), (File)localObject);
        Part file = Part.createFormData("file", ((File) localObject).getName(), localRequestBody);
        this.partList[i] = file;
      }
      i += 1;
    }
  }
  
  public void buildProgressDialog()
  {
    if (this.progressDialog == null)
    {
      this.progressDialog = new ProgressDialog(this);
      this.progressDialog.setProgressStyle(0);
    }
    this.progressDialog.setMessage("提交中...");
    this.progressDialog.setCancelable(true);
    this.progressDialog.show();
  }
  
  public void cancelProgressDialog()
  {
    if ((this.progressDialog != null) && (this.progressDialog.isShowing())) {
      this.progressDialog.dismiss();
    }
  }
  
  public void getOrderMsg()
  {
    Net.get().getOrderDetail(this.orderId, this.userId).subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new CommonObserver<OrderDetail>() {
              @Override
              protected void onError(String errorMsg) {

              }

              @Override
              protected void onSuccess(OrderDetail orderDetail) {

              }
            });
  }
  
  public String getRealFilePath(Context paramContext, Uri paramUri)
  {
    if (paramUri == null) {
      return null;
    }

    return "";
//    String str = paramUri.getScheme();
//    Object localObject2 = null;
//    Object localObject3 = null;
//    String localObject1;
//    if (str == null) {
//      localObject1 = paramUri.getPath();
//    }
//    for (;;)
//    {
//      this.realPicUrlList.add(localObject1);
//      return (String)localObject1;
//      if ("file".equals(str))
//      {
//        localObject1 = paramUri.getPath();
//      }
//      else
//      {
//        localObject1 = localObject3;
//        if ("content".equals(str))
//        {
//          str = paramUri.getAuthority();
//          if (str.equals("media"))
//          {
//            paramContext = paramContext.getContentResolver().query(paramUri, new String[] { "_data" }, null, null, null);
//            localObject1 = localObject3;
//            if (paramContext != null)
//            {
//              localObject1 = localObject2;
//              if (paramContext.moveToFirst())
//              {
//                int i = paramContext.getColumnIndex("_data");
//                localObject1 = localObject2;
//                if (i > -1) {
//                  localObject1 = paramContext.getString(i);
//                }
//              }
//              paramContext.close();
//            }
//          }
//          else
//          {
//            localObject1 = localObject3;
//            if (str.equals("com.jl.jlapp.publish.MyFileProvider")) {
//              localObject1 = Environment.getExternalStorageDirectory() + "/Pictures/" + paramUri.getLastPathSegment();
//            }
//          }
//        }
//      }
//    }
  }
  
  public void handleImgPicker()
  {
    this.list = new ArrayList();
    this.pickerView.setImageLoaderInterface(new Loader());
    this.pickerView.setNewData(this.list);
    this.pickerView.setShowAnim(true);
    this.pickerView.setMaxNum(2);
    this.pickerView.setOneLineShowNum(4);
    this.pickerView.setmDelLabel(2131165417);
    this.pickerView.setmAddLabel(2131165621);
    this.pickerView.setmPicSize(200);
    this.pickerView.setPickerListener(new ImageShowPickerListener()
    {
      public void addOnClickListener(int paramAnonymousInt)
      {
        if ((ActivityCompat.checkSelfPermission(UnderlineActivity.this, "android.permission.READ_EXTERNAL_STORAGE") != 0) || (ActivityCompat.checkSelfPermission(UnderlineActivity.this, "android.permission.READ_EXTERNAL_STORAGE") != 0))
        {
          AndPermission.with(UnderlineActivity.this).requestCode(300).permission(new String[] { "android.permission.READ_EXTERNAL_STORAGE", "android.permission.WRITE_EXTERNAL_STORAGE" }).rationale(UnderlineActivity.this.rationaleListener).callback(this).start();
          return;
        }
        Matisse.from(UnderlineActivity.this).choose(MimeType.of(MimeType.JPEG, new MimeType[] { MimeType.PNG })).countable(true).maxSelectable(paramAnonymousInt + 1).capture(true).captureStrategy(new CaptureStrategy(true, "com.jl.jlapp.publish.MyFileProvider")).restrictOrientation(-1).gridExpectedSize(300).thumbnailScale(0.85F).imageEngine(new PicassoEngine()).theme(R.style.Matisse_Dracula).forResult(233);
      }
      
      public void delOnClickListener(int paramAnonymousInt1, int paramAnonymousInt2)
      {
        UnderlineActivity.this.realPicUrlList.remove(paramAnonymousInt1);
      }
      
      public void picOnClickListener(List<ImageShowPickerBean> paramAnonymousList, int paramAnonymousInt1, int paramAnonymousInt2)
      {
        Intent intent = new Intent(UnderlineActivity.this, PhotoViewActivity.class);
        intent.putExtra("picUrl", (String)UnderlineActivity.this.realPicUrlList.get(paramAnonymousInt1));
        intent.putExtra("flag", 1);
        UnderlineActivity.this.startActivity(intent);
      }
    });
    this.pickerView.show();
    AndPermission.with(this).requestCode(300).permission(new String[] { "android.permission.READ_EXTERNAL_STORAGE", "android.permission.WRITE_EXTERNAL_STORAGE", "android.permission.CAMERA" }).rationale(this.rationaleListener).callback(this).start();
    this.pickerView.getDataList();
  }
  
  protected void onActivityResult(int paramInt1, int paramInt2, Intent paramIntent)
  {
    super.onActivityResult(paramInt1, paramInt2, paramIntent);
    if ((paramInt1 == 233) && (paramInt2 == -1))
    {
      List<Uri> uris = Matisse.obtainResult(paramIntent);
      if (uris.size() == 1) {
        this.pickerView.addData(new ImageBean(getRealFilePath(this, uris.get(0))));
      }else {
        ArrayList arrayList = new ArrayList();
        Object localObject = uris.iterator();
        while (((Iterator)localObject).hasNext()) {
          arrayList.add(new ImageBean(getRealFilePath(this, (Uri)((Iterator)localObject).next())));
        }
        this.pickerView.addData(arrayList);
      }

    }
    else
    {
      return;
    }

  }
  
  @OnClick({R.id.btn_return})
  public void onClick(View paramView)
  {

    if (this.isNotOvertime)
    {
      this.clearHistorySearhPopu = new ClearHistorySearhPopu(this, new OnClickListener()
      {
        public void onClick(View paramAnonymousView)
        {
          if (UnderlineActivity.this.fromDetailPage != 1)
          {
            Intent intent = new Intent(UnderlineActivity.this, OrderDetailActivity.class);
            intent.putExtra("orderId", UnderlineActivity.this.orderId);
            UnderlineActivity.this.startActivity(intent);
          }
          UnderlineActivity.this.clearHistorySearhPopu.dismiss();
          UnderlineActivity.this.finish();
        }
      }, Integer.valueOf(12));
      this.clearHistorySearhPopu.showAtLocation(findViewById(R.id.underline_page), 17, 0, 0);
      return;
    }
    finish();
  }
  
  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setContentView(R.layout.activity_underline);
    ButterKnife.bind(this);
    Tools.finishAll();
    this.tvRemitterAccountDetails.setInputType(3);
    this.userId = getSharedPreferences("JLAppData", 0).getInt("userId", 0);
    Intent intent = getIntent();
    this.payMoney = intent.getDoubleExtra("payMoney", -1.0D);
    this.orderId = intent.getIntExtra("orderId", 0);
    this.orderNo = intent.getStringExtra("orderNo");
    this.postagePayType = intent.getIntExtra("postagePayType", -1);
    this.fromDetailPage = intent.getIntExtra("fromDetailPage", -1);
    if ((this.payMoney != -1.0D) && (this.orderId != -1) && (this.orderNo != null) && (this.orderNo != "") && (this.postagePayType != -1))
    {
      if (this.payMoney >= 50000.0D)
      {
        getOrderMsg();
        setData();
        setAdapter();
        return;
      }
      Toast.makeText(this, "数据错误", Toast.LENGTH_SHORT).show();
      return;
    }
    Toast.makeText(this, "页面传值错误", Toast.LENGTH_SHORT).show();
  }
  
  public boolean onKeyDown(int paramInt, KeyEvent paramKeyEvent)
  {
    if (paramInt == 4)
    {
      if (this.isNotOvertime)
      {
        this.clearHistorySearhPopu = new ClearHistorySearhPopu(this, new OnClickListener()
        {
          public void onClick(View paramAnonymousView)
          {
            if (UnderlineActivity.this.fromDetailPage != 1)
            {
              Intent intent = new Intent(UnderlineActivity.this, OrderDetailActivity.class);
              intent.putExtra("orderId", UnderlineActivity.this.orderId);
              UnderlineActivity.this.startActivity(intent);
            }
            UnderlineActivity.this.clearHistorySearhPopu.dismiss();
            UnderlineActivity.this.finish();
          }
        }, Integer.valueOf(12));
        this.clearHistorySearhPopu.showAtLocation(findViewById(R.id.underline_page), 17, 0, 0);
        return true;
      }
      finish();
      return true;
    }
    return super.onKeyDown(paramInt, paramKeyEvent);
  }
  
  public void setAdapter()
  {
    Object localObject = new CustomLanearLayoutManager(this);
    ((CustomLanearLayoutManager)localObject).setScrollEnabled(false);
    this.rlvOrderDetails.setLayoutManager((LayoutManager)localObject);
    localObject = new OrderDetailsAdapter(R.layout.item_order_details, this.models);
    this.rlvOrderDetails.setAdapter((Adapter)localObject);
  }
  
  public void setData()
  {
    this.tvSuccess.setText("您的订单(订单号:" + this.orderNo + ")已提交成功");
    this.models = new ArrayList();
    String[] arrayOfString = new String[5];
    arrayOfString[0] = "订单号：";
    arrayOfString[1] = "待支付金额：";
    arrayOfString[2] = "收款人：";
    arrayOfString[3] = "开户行：";
    arrayOfString[4] = "账号：";
    Evaluate localEvaluate;
    if (this.postagePayType == 1)
    {
     String str1 = this.orderNo;
      String str2 = "¥" + this.payMoney + "(订单超出配送范围，运费货到付款)";
    int  i = 0;
      while (i < arrayOfString.length)
      {
        localEvaluate = new Evaluate();
        localEvaluate.setTitle(arrayOfString[i]);
        localEvaluate.setScroe(new String[] { str1, str2, "北京食讯帮食品发展有限公司", "中国光大银行股份有限公司北京清华园支行", "35360188000020130" }[i]);
        this.models.add(localEvaluate);
        i += 1;
      }
      handleImgPicker();
      submitBtnClick();
      return;
    }
    String str1 = this.orderNo;
    String str2 = "¥" + this.payMoney;
    int i = 0;
    while (i < arrayOfString.length)
    {
      localEvaluate = new Evaluate();
      localEvaluate.setTitle(arrayOfString[i]);
      localEvaluate.setScroe(new String[] { str1, str2, "北京食讯帮食品发展有限公司", "中国光大银行股份有限公司北京清华园支行", "35360188000020130" }[i]);
      this.models.add(localEvaluate);
      i += 1;
    }
    handleImgPicker();
    submitBtnClick();
  }
  
  public void submitBtnClick()
  {
    this.offlinePaymentSubmitBtn.setOnClickListener(new OnClickListener()
    {
      public void onClick(View paramAnonymousView)
      {
        UnderlineActivity.this.remitterName = UnderlineActivity.this.tvRemitterNameDetails.getText().toString().trim();
        UnderlineActivity.this.remitterAccount = UnderlineActivity.this.tvRemitterAccountDetails.getText().toString().trim();
        if ((UnderlineActivity.this.userId == 0) || ("".equals(UnderlineActivity.this.orderNo)) || (UnderlineActivity.this.payMoney < 50000.0D)) {
          Toast.makeText(UnderlineActivity.this, "内部错误", Toast.LENGTH_SHORT).show();
        }else if ((UnderlineActivity.this.userId <= 0) || ("".equals(UnderlineActivity.this.orderNo)) || (UnderlineActivity.this.payMoney < 50000.0D) || ("".equals(UnderlineActivity.this.remitterName)) || ("".equals(UnderlineActivity.this.remitterAccount))){
          if ("".equals(UnderlineActivity.this.remitterName))
          {
            Toast.makeText(UnderlineActivity.this, "请输入汇款人姓名", Toast.LENGTH_SHORT).show();
            return;
          }
          if ("".equals(UnderlineActivity.this.remitterAccount))
          {
            Toast.makeText(UnderlineActivity.this, "请输入汇款人账号", Toast.LENGTH_SHORT).show();
            return;
          }
          if (UnderlineActivity.this.realPicUrlList.size() == 0)
          {
            Toast.makeText(UnderlineActivity.this, "请上传支付凭证", Toast.LENGTH_SHORT).show();
            return;
          }
        }

        UnderlineActivity.this.buildProgressDialog();
        UnderlineActivity.this.photo(UnderlineActivity.this.realPicUrlList);
        UnderlineActivity.this.offlinePaymentSubmitBtn.setClickable(false);
        UnderlineActivity.this.offlinePaymentSubmitBtn.setTextColor(UnderlineActivity.this.getResources().getColor(R.color.font_grey));
        Net.get().uploadPhoto(UnderlineActivity.this.partList)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CommonObserver<ImgUploadModel>() {
                  @Override
                  protected void onError(String errorMsg) {

                  }

                  @Override
                  protected void onSuccess(ImgUploadModel imgUploadModel) {

                  }
                });
      }
    });
  }
}


/* Location:              /Users/davidzhang/Documents/decompileApk/jlfood-dex2jar.jar!/com/jl/jlapp/mvp/activity/UnderlineActivity.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */